检查^{}和^{}模块以列出文件夹内容(walk,listdir)并使用路径名(abspath,basename等)
另外,^{}还有一些有趣的复制功能。签出copyfile,并根据从excel文件中读取的数据指定dst参数。在
您可能需要一些类似这样的高级代码:for subfolder_name in os.listdir(MAIN_FOLDER):
# exercise left to reader: filter out non-folders
subfolder_path = os.path.join(MAIN_FOLDER, subfolder_name)
for excel_file_name in os.listdir(os.path.join(MAIN_FOLDER, subfolder_name)):
# exercise left to reader: filter out non-excel-files
excel_file_path = os.path.join(subfolder_path, excel_file_name)
new_excel_file_name = extract_filename_from_excel_file(excel_file_path)
new_excel_file_path = os.path.join(NEW_MAIN_FOLDER, subfolder_name,
new_excel_file_name)
shutil.copyfile(excel_file_path, new_excel_file_path)
您必须使用我提到的站点中的xlrd模块自己提供extract_filename_from_excel_file。在